<!--
 * @Author: your name
 * @Date: 2021-08-03 13:36:05
 * @LastEditTime: 2021-08-12 13:26:42
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \getHome (2)\src\components\discounts\amend.vue
-->
<!--员工账号管理-->
<template>
  <div>
    <div class="herdertop">
      <img src="../../assets/top.png" alt="" class="topImg" />
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>员工管理</el-breadcrumb-item>
        <el-breadcrumb-item>员工账号管理</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="center" style="padding-top: 0;">
      <div class="hander">员工账号管理</div>
      <div class="entirety">
        <div style="padding:10px;">
          <div class="search" style="margin-bottom: 0px;">
            <!-- 员工搜索信息 -->
            <div class="userSearch marginRight">
              <el-select
                v-model="userSearch"
                placeholder="请选择"
                @change="changeSelect"
              >
                <el-option
                  v-for="item in staffSearch"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
              <el-input v-model="searchValue" placeholder="请输入"></el-input>
              <!-- <el-button
              icon="el-icon-search"
              @click="searchForUserInformation"
            ></el-button> -->
            </div>

            <!--  账号状态搜索信息 -->

            <div class="demo-input-suffix">
              账号状态
              <el-select clearable v-model="StateData" placeholder="请选择">
                <el-option
                  v-for="item in business"
                  :key="item.statusCode"
                  :label="item.statusName"
                  :value="item.statusCode"
                >
                </el-option>
              </el-select>
            </div>

            <div class="news">
              <!-- <el-button size="medium" @click.native.prevent="isExport(tableData)"
              >导出</el-button
            > -->
              <!-- <el-button @click="add">跳转</el-button> -->
              <el-button
                size="medium"
                :disabled="multipleSelection.length == 0 ? true : false"
              >
                <download-excel
                  :data="multipleSelection"
                  :fields="json_fields"
                  name="用户账号表.xls"
                >
                  导出</download-excel
                >
              </el-button>
              <el-button @click="goToNewly()">新增员工</el-button>

              <!-- <el-button size="medium" @click="dialogFormVisible = true"
              >新建员工</el-button
            > -->
            </div>
          </div>
          <div class="demo-input-suffix" style="margin-top:15px">
            <el-button
              style="background-color:#fd804c;color: #fff;"
              @click.native.prevent="isSelect"
              >查询</el-button
            >
            <el-button type="warning" @click.native.prevent="isEmpty"
              >清空</el-button
            >
          </div>
        </div>
        <el-dialog title="新建员工" :visible.sync="dialogFormVisible">
          <el-form :model="form">
            <el-form-item label="活动名称" :label-width="formLabelWidth">
              <el-input v-model="form.name" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="活动区域" :label-width="formLabelWidth">
              <el-select v-model="form.region" placeholder="请选择">
                <el-option label="区域一" value="shanghai"></el-option>
                <el-option label="区域二" value="beijing"></el-option>
              </el-select>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button
              style="background-color:#fd804c;color: #fff;"
              @click="dialogFormVisible = false"
              >确 定</el-button
            >
          </div>
        </el-dialog>
      </div>
      <!--  员工列表栏位-->
      <div class="entirety">
        <el-table
          ref="multipleTable"
          :data="tableData"
          tooltip-effect="dark"
          style="width: 100%"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55"> </el-table-column>
          <el-table-column prop="nickname" label="员工姓名" width="120">
            <template slot-scope="scope">
              <div>
                {{ scope.row.nickname }}
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="userName" label="登录账号">
            <template slot-scope="scope">
              <div>
                {{ scope.row.userName }}
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="staffStatus" label="状态" width="120">
            <template slot-scope="scope">
              <div>
                {{ scope.row.staffStatus }}
              </div>
            </template>
          </el-table-column>
          <el-table-column fixed="right" label="操作" width="170">
            <template slot-scope="scope">
              <el-button
                v-if="scope.row.staffStatus == '正常'"
                @click.native.prevent="isFrozen(scope.row.staffCode)"
                style="color: #fc9e76;"
                type="text"
                size="small"
              >
                冻结
              </el-button>
              <el-button
                v-if="scope.row.staffStatus != '正常'"
                @click.native.prevent="isThaw(scope.row.staffCode)"
                style="color: #fc9e76;"
                type="text"
                size="small"
              >
                解冻
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="block">
          <div class="left"></div>
          <div class="right">
            <el-pagination
              layout="total, sizes, prev, pager, next, jumper"
              class="page"
              @size-change="sizeChangeHandle"
              @current-change="currentChangeHandle"
              :current-page="pageIndex"
              :page-size="pageSize"
              :total="total"
            >
            </el-pagination>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      json_fields: {
        //导出Excel表格的表头设置
        员工姓名: "nickname",
        登录账号: "userName",
        员工状态: "staffStatus"
      },

      pageIndex: 1,
      pageSize: 20,
      total: 0,
      dialogTableVisible: false,
      dialogFormVisible: false,
      tableData: [],
      form: {
        name: "",
        region: "",
        date1: "",
        date2: "",
        delivery: false,
        type: [],
        resource: "",
        desc: ""
      },
      staffName: "",
      staffPhone: "",
      searchValue: "",
      userSearch: 0,

      formLabelWidth: "120px",
      staffSearch: [
        { value: 0, label: "员工姓名" },
        { value: 1, label: "登录账号" }
      ],
      StateData: "",
      business: [
        {
          statusCode: "1",
          statusName: "正常"
        },
        {
          statusCode: "2",
          statusName: "冻结"
        }
      ],
      multipleSelection: []
    };
  },
  activated() {
    this.DetailByPage();
  },

  methods: {
    isSelect() {
      //console.log("userSearch,,,,dsdsd,", this.userSearch);
      if (this.userSearch === 0) {
        this.staffName = this.searchValue || "";
      } else {
        this.staffPhone = this.searchValue || "";
      }

      (this.pageIndex = 1), (this.pageSize = 20), this.DetailByPage();
    },

    isEmpty() {
      (this.pageIndex = 1),
        (this.pageSize = 20),
        (this.total = 0),
        (this.staffName = ""),
        (this.staffPhone = ""),
        (this.searchValue = ""),
        (this.userSearch = 0),
        (this.StateData = ""),
        this.DetailByPage();
    },
    // 跳转页面
    add() {
      this.$router.push({
        path: "/arrStaff"
      });
    },
    handleSelectionChange(val) {
      //console.log("handleSelectionChange,,,,,,,", val);
      this.multipleSelection = val;
    },

    // 切换搜索条件清空数据
    changeSelect() {
      (this.searchValue = ""), (this.staffName = ""), (this.staffPhone = "");
    },

    // 精准模糊查找
    searchForUserInformation() {
      //console.log("userSearch,,,,dsdsd,", this.userSearch);
      if (this.userSearch === 0) {
        this.staffName = this.searchValue || "";
      } else {
        this.staffPhone = this.searchValue || "";
      }
      this.DetailByPage();
    },
    //冻结
    isFrozen(staffCode) {
      this.$confirm("是否冻结?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$http({
            url:
              "/staffadmin/homeService/staffManager/updateStaffLoginAccountStatus",
            method: "POST",
            data: {
              staffCode,
              staffStatus: 2
            }
          }).then(res => {
            if (res.success === 0) {
              this.$message.error(res.errorMsg);
            } else {
              this.$message.success("冻结成功");
              this.DetailByPage();
            }
          });
        })
        .catch(() => {});
    },
    //解冻
    isThaw(staffCode) {
      this.$confirm("是否解冻?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$http({
            url:
              "/staffadmin/homeService/staffManager/updateStaffLoginAccountStatus",
            method: "POST",
            data: {
              staffCode,
              staffStatus: 1
            }
          }).then(res => {
            if (res.success === 0) {
              this.$message.error(res.errorMsg);
            } else {
              this.$message.success("解冻成功");
              this.DetailByPage();
            }
          });
        })
        .catch(() => {});
      this.DetailByPage();
    },
    //导出
    isExport(tableData) {
      //console.log(tableData);
    },
    goToNewly() {
      this.$router.push({
        path: "/newly"
      });
    },

    // 更换状态数据
    changeState(val) {
      //console.log(val);

      this.StateData = val || "";
      this.DetailByPage();
    },
    //分页获取优惠券模板列表接口调用
    DetailByPage() {
      this.$http({
        url: `staffadmin/homeService/staffManager/fetchStaffLoginAccountList`,
        method: "GET",
        params: {
          staffStatus: this.StateData,
          staffName: this.staffName,
          staffPhone: this.staffPhone,
          page: this.pageIndex,
          size: this.pageSize
        }
      }).then(res => {
        this.tableData = res.list;

        this.total = parseInt(res.total);
      });
    },

    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.DetailByPage();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.DetailByPage();
    }
  }
};
</script>
<style scoped lang="scss">
.block {
  width: 100%;
  height: 70px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-sizing: border-box;
  padding: 0 10px 0 10px;
}
.left {
  font-size: 15px;
}
.hander {
  width: 100%;
  height: 50px;
  line-height: 50px;
  font-size: 20px;
  font-weight: 900;
}
.herdertop {
  height: 8vh;
  display: flex;
  align-items: center;
  padding: 0 20px;
  box-sizing: border-box;
}
.topImg {
  margin-right: 20px;
}
.news {
  margin-left: 16%;
}
.entirety {
  width: 95%;
  margin: 10px;
  // border: 7px solid #fafafa;
  border: 7px solid #ebeef1;
  border-radius: 10px;
  .basic {
    font-size: 18px;
    font-weight: 900;
    margin-top: 2%;
    margin-bottom: 1%;
    margin-left: 1%;
  }
}

.overall {
  width: 100%;
  height: auto;
  display: flex;

  justify-content: space-between;
  margin-top: 3%;
  .left {
    width: 20%;
    height: auto;
  }
  .right {
    width: 80%;
    height: auto;
  }
}
.demo-input-suffix {
  margin-left: 2%;
}
.select {
  width: 65%;
  height: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .dialog-footer,
  .choice {
    margin-left: 2%;
  }
}
.userSearch {
  display: flex;
  /deep/ .el-input__inner {
    box-sizing: border-box;
    height: 40px;
    border-radius: 0;
    width: 132px;
    border: 1px solid #dcdfe6;
  }
  /deep/ .el-icon-arrow-up:before {
    position: relative;
    top: -4px;
  }
  /deep/ .el-button {
    height: 40px;
    border-radius: 0;
    background-color: #fff;
    border: 1px solid #dcdfe6;
    border-left: none;
    border-top-right-radius: 4px;
    border-bottom-right-radius: 4px;
    position: relative;
    .el-icon-search {
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
    }
  }
  /deep/ .el-input--suffix .el-input__inner {
    border-right: none;
  }
  /deep/ .el-input--suffix .el-input__inner {
    border-top-left-radius: 4px;
    border-bottom-left-radius: 4px;
  }
}
.selects {
  width: 55%;
  height: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .dialog-footer,
  .choice {
    margin-left: 2%;
  }
}

/deep/ .but {
  background: #fd7097;
  color: #fff;
  margin-bottom: 1%;
}
</style>
